<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>更多优惠券</title>
  <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
  <meta content="yes" name="apple-mobile-web-app-capable"/>
  <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
  <meta content="telephone=no" name="format-detection"/>
  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
  <script src="__STATIC__/layer/layer.js"></script>
</head>
<body>
    {if condition="empty($coupon)"}
        没有更多优惠券
    {else /}
        {foreach name="coupon" item="v"}
            {if condition="$v.is_received eq 0"}
            <div>
                <span>￥{$v.reduce}</span>
                <span>{$v.morethan}</span>
            </div>
            <a href="javascript:;" onclick="receive_coupon({$v.id})">领取</a>
            {else /}
            <div>
                <span>￥{$v.reduce}</span>
                <span>{$v.morethan}</span>
                <span>(已领取)</span>
            </div>
            {/if}
        {/foreach}
    {/if}
</body>
</html>
<script>
    /**
     *  领裙优惠券
     */
    function receive_coupon(id){
        $.post("{:url('Index/receive_coupon')}",
            {id:id},
            function(data){
                if(data.code == 1){
                    alert('领取成功');
                }else{
                    alert(data.msg);
                    if(data.data == 7){
                        window.location.href = "{:url('Login/loginin')}";
                    }
                }
            }
        );
    }
</script>